package com.chris.libs.base.x.mvpp.event;

import org.greenrobot.eventbus.EventBus;

import java.io.Serializable;

/**
 * @author Chris Chan
 * on 2019/7/9 17:27
 * use for:
 */
public class BaseEvent<T> implements Serializable {
    public static final int EVENT_SUCCESS = 0x00000001;
    public static final int EVENT_ERROR = 0x00000002;

    public int code = EVENT_SUCCESS;//消息状态码
    public String tag;//标记，用于区别，同一处接收避免使用相同的标记
    public String msg;//提示信息
    public T data;//封装的传递数据

    public BaseEvent() {
    }

    public BaseEvent(int code, String tag, String msg, T data) {
        this.code = code;
        this.tag = tag;
        this.msg = msg;
        this.data = data;
    }

    public static <T> BaseEvent<T> create(int code, String tag, String msg, T data) {
        return new BaseEvent<>(code, tag, msg, data);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getTag() {
        return tag;
    }

    public void setTag(String tag) {
        this.tag = tag;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public void publish() {
        EventBus.getDefault().post(this);
    }
}
